<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<%-- <jsp:include page="/include.jsp"/>  --%>
<div class="easyui-tabs" id="assign_tabs">
    <div title="人员自动入住分配信息">
        <input id="auto_emp_id" value="${emp.id}" type="hidden">
        <input id="auto_emp_name" value="${emp.name}" type="hidden">
        <input id="auto_room_id" value="${props.room_id}" type="hidden">
        <input id="auto_room_no" value="${props.room_no}" type="hidden">
        <input id="auto_room_region" value="${props.room_region}" type="hidden">
        <input id="auto_room_deck" value="${props.room_deck}" type="hidden">
        <input id="auto_room_type" value="${props.room_type}" type="hidden">
        <input id="auto_bed_id" value="${props.bed_id}" type="hidden">
        <input id="auto_bed_no" value="${props.bed_no}" type="hidden">

                    <span class="required">*</span>入住时间：&nbsp;
                    <input id="startStay" name="startStay" type="text" class="easyui-datetimebox"  value="${stayTime}"data-options="required:true,missingMessage:'请输入入住时间'"/>
                    <span class="required">*</span>退房时间：&nbsp;
            
                    <input id="endStay" name="endStay" type="text" class="easyui-datetimebox" value="${outTime}" data-options="required:true,missingMessage:'请输入退房时间'"/>   
       
  
        <div style="height:300px;">
        	          
            <table id="stay-datagrid"></table>
        </div>
        
        
        
    </div>
    <div title="手动分配房间">
        <form id="stay_datasource_query_form" name="stay_datasource_query_form" method="post">
            <table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
            <tr>
                <td style="width:10%;text-align:left;" nowrap="nowrap">
                    <label for="datasource_datsourcename"> 舱室编号：</label>
                    <input type="text" id="datasource_datsourcename" name="roomNo" class="easyui-validatebox"
                           data-options="validType:'specialCharFilter'"/>
                </td>
                <td style="width:15%;text-align:left;" nowrap="nowrap">
                    <label for="list_select_deckinfo">    甲&nbsp;&nbsp;板：</label>
                    <input type="text" id="list_select_deckinfo" name="deck"
                   			class="easyui-combobox" data-options="validType:'specialCharFilter'"/>
                </td>
                <td colspan="2" style="width:25%;text-align:right;" nowrap="nowrap">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td style="width:10%;text-align:left;" nowrap="nowrap">
                    <label for="list_select_deviceType"> 区&nbsp;&nbsp;域：</label>
                    <input type="text" id="list_select_reqioninfo" name="area"
                   		class="easyui-combobox" data-options="validType:'specialCharFilter'"/>
                </td>
                <td style="width:15%;text-align:left;" nowrap="nowrap">
                    <label for="list_select_type">     种&nbsp;&nbsp;类：</label>
                    <input type="text" id="list_select_type" name="type"
                   class="easyui-combobox" data-options="validType:'specialCharFilter'"/>
                </td>
                <td colspan="2" style="width:25%;text-align:left;" nowrap="nowrap">
                    &nbsp;
                </td>
            
                
                <td colspan="2" style="width:25%;text-align:left;" nowrap="nowrap">
                    <input type="button" id="btnQuery" onclick=doStayQuery() value="查 询" class="search_btn"/>
                    <input type="button" id="btnReset" onclick=doStayReset() value="重 置" class="reset_btn"/>
                </td>
            </tr>
            <tr>
            	<td colspan="2" style="width:25%;text-align:left;" nowrap="nowrap">
                    &nbsp;
                </td>
                
            	</tr>
        </table>
        </form>
        <div style="height:300px;">
        	<span class="required">*</span>入住时间：
                    <input id="startStay1" name="startStay1" type="text" value="${stayTime}" class="easyui-datetimebox" data-options="required:true,missingMessage:'请输入入住时间'">
                    <span class="required">*</span>退房时间：
                    <input id="endStay1" name="endStay1" type="text" value="${outTime}" class="easyui-datetimebox" data-options="required:true,missingMessage:'请输入退房时间'">  
            <table id="stay-datagrid1"></table>
            
           
        </div>
    </div>
</div>

<script type="text/javascript">
  function doStayQuery() {
        if ($("#stay_datasource_query_form").form("validate")) {
            $("#stay-datagrid1").datagrid('options').queryParams = serializeObject($('#stay_datasource_query_form')); //把查询条件赋值给datagrid内部变量
            $("#stay-datagrid1").datagrid('load'); //重新加载
        }
    }
    
    //重置查询条件
function doStayReset() {
 // alert("==================-----------");
    $('#stay_datasource_query_form').form('reset');
}
   
    
$(function () {
     //查询按纽绑定事件
  //  $('#btnQuery').bind('click', doStayQuery);
  //  alert("==================");
    //重置按纽绑定事件
   // $('#btnReset').bind('click', doStayReset);
    
    $('#stay-datagrid1').datagrid({
        url: '${pageContext.request.contextPath}/cnbdw/roomAction!getFullDatasourceList.action',
        border: false,
        singleSelect:true,
        fitColumns: true,
        pagination: true,
        height: 300,
        pageList: [10, 20, 30],
        rownumbers: true,
        sortName: 'id',
        sortOrder: 'desc',
        striped: true,
        columns: [
            [
                {field: 'roomNo', title: '房间编号', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (value == '') {
                        return '--'
                    }
                    return value;
                }},
                {field: 'deckInfo', title: '甲板', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (rowData.roomType == null) {
                        return '--'
                    }
                    return getName(rowData.bedInfos[0].room.deckInfo, $('#stay-datagrid1').datagrid('getData'));
                }},
                {field: 'roomType', title: '舱室种类', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (rowData.roomType == null) {
                        return '--'
                    }
                    return getName(rowData.bedInfos[0].room.roomType, $('#stay-datagrid1').datagrid('getData'));
                }},
                 {field: 'remark', title: '备注', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (value == '') {
                        return '--'
                    }
                    return value;
                }},
                {field: 'beds', title: '可入住人数', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (rowData.bedInfos == null || rowData.bedInfos.length == 0) {
                        return '--'
                    }
                    var size = rowData.bedInfos.length;
                    $.each(rowData.bedInfos, function (index, item) {
                        if (item.employee) {
                            size--;
                        }
                    });
                    return size;
                }},
                {field: 'haveToStay', title: '已入住人数', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (rowData.bedInfos == null || rowData.bedInfos.length == 0) {
                        return '--'
                    }
                    var size = 0;
                    $.each(rowData.bedInfos, function (index, item) {
                        if (item.employee) {
                            size++;
                        }
                    });
                    return size;
                }},
                {field: 'stayEmp', title: '入住人员', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (rowData.bedInfos == null || rowData.bedInfos.length == 0) {
                        return '--'
                    }
                    var emps = [];
                    $.each(rowData.bedInfos, function (index, item) {
                        if (item.employee) {
                            emps.push(item.employee.name);
                        }
                    });
                    return emps.join(", ");
                }}
            ]
        ]
    });
    
     $('#list_select_type').combobox({
            url:'${pageContext.request.contextPath}/roomTypeAction!getTypeSelectData.action',
            valueField:'id',
            textField:'name',
            editable:false
        });
        $('#list_select_reqioninfo').combobox({
            url:'${pageContext.request.contextPath}/regionInfoAction!getRegionInfoSelectData.action',
            valueField:'id',
            textField:'name',
            editable:false
        });
        $('#list_select_deckinfo').combobox({
            url:'${pageContext.request.contextPath}/deckInfoAction!getDeckInfoSelectData.action',
            valueField:'id',
            textField:'name',
            editable:false
        });
    
     //初始化主列表
    $('#stay-datagrid').datagrid({
        url: '${pageContext.request.contextPath}/cnbdw/roomAction!getOneDatasourceList.action',
        border: false,
        singleSelect:true,
        fitColumns: true,
       // pagination: true,
        height: 300,
        pageList: [10, 20, 30],
        rownumbers: true,
        sortName: 'id',
        sortOrder: 'desc',
        striped: true,
        columns: [
            [
                {field: 'roomNo', title: '房间编号', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (value == '') {
                        return '--'
                    }
                    return value;
                }},
                {field: 'deckInfo', title: '甲板', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (rowData.roomType == null) {
                        return '--'
                    }
                    
                     var emps = [];
                    $.each(rowData.roomType, function (index, item) {
                        if (item.employee) {
                            emps.push(item.employee.name);
                        }
                    });
                    return rowData.bedInfos[0].room.deckInfo.name;
                }},
                 {field: 'roomType', title: '舱室类型', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (rowData.roomType == null) {
                        return '--'
                    }
                    return rowData.bedInfos[0].room.roomType.name;
                }},
                 {field: 'remark', title: '备注', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (value == '') {
                        return '--'
                    }
                    return value;
                }},
                {field: 'beds', title: '可入住人数', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (rowData.bedInfos == null || rowData.bedInfos.length == 0) {
                        return '--'
                    }
                    var size = rowData.bedInfos.length;
                    $.each(rowData.bedInfos, function (index, item) {
                        if (item.employee) {
                            size--;
                        }
                    });
                    return size;
                }},
                {field: 'haveToStay', title: '已入住人数', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (rowData.bedInfos == null || rowData.bedInfos.length == 0) {
                        return '--'
                    }
                    var size = 0;
                    $.each(rowData.bedInfos, function (index, item) {
                        if (item.employee) {
                            size++;
                        }
                    });
                    return size;
                }},
                {field: 'stayEmp', title: '入住人员', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (rowData.bedInfos == null || rowData.bedInfos.length == 0) {
                        return '--'
                    }
                    var emps = [];
                    $.each(rowData.bedInfos, function (index, item) {
                        if (item.employee) {
                            emps.push(item.employee.name);
                        }
                    });
                    return emps.join(", ");
                }}
            ]
        ]
    });
    
    });
    $('#assign_tabs').tabs({
        onSelect: function(title,index){
            if(index == 0){
           // 	alert("title1::"+title);
                $("#stay-datagrid").datagrid('clearSelections');
            }
            else  if(index == 1){
           // 	alert("title2::"+title);
                $("#stay-datagrid1").datagrid('clearSelections');
            }
        }
    });
    
    
     /*$('#stay-datagrid1').datagrid({
        url: '${pageContext.request.contextPath}/cnbdw/roomAction!getFullDatasourceList.action',
        border: false,
        singleSelect:true,
        fitColumns: true,
        pagination: true,
        height: 300,
        pageList: [10, 20, 30],
        rownumbers: true,
        sortName: 'id',
        sortOrder: 'desc',
        striped: true,
        columns: [
            [
                {field: 'roomNo', title: '房间编号', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (value == '') {
                        return '--'
                    }
                    return value;
                }},
                {field: 'deckInfo', title: '甲板', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (rowData.roomType == null) {
                        return '--'
                    }
                    return getName(rowData.bedInfos[0].room.deckInfo, $('#stay-datagrid1').datagrid('getData'));
                }},
                {field: 'roomType', title: '舱室种类', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (rowData.roomType == null) {
                        return '--'
                    }
                    return getName(rowData.bedInfos[0].room.roomType, $('#stay-datagrid1').datagrid('getData'));
                }},
                {field: 'beds', title: '可入住人数', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (rowData.bedInfos == null || rowData.bedInfos.length == 0) {
                        return '--'
                    }
                    var size = rowData.bedInfos.length;
                    $.each(rowData.bedInfos, function (index, item) {
                        if (item.employee) {
                            size--;
                        }
                    });
                    return size;
                }},
                {field: 'haveToStay', title: '已入住人数', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (rowData.bedInfos == null || rowData.bedInfos.length == 0) {
                        return '--'
                    }
                    var size = 0;
                    $.each(rowData.bedInfos, function (index, item) {
                        if (item.employee) {
                            size++;
                        }
                    });
                    return size;
                }},
                {field: 'stayEmp', title: '入住人员', align: 'left', width: 150, formatter: function (value, rowData, rowIndex) {
                    if (rowData.bedInfos == null || rowData.bedInfos.length == 0) {
                        return '--'
                    }
                    var emps = [];
                    $.each(rowData.bedInfos, function (index, item) {
                        if (item.employee) {
                            emps.push(item.employee.name);
                        }
                    });
                    return emps.join(", ");
                }}
            ]
        ]
    });
    $('#assign_tabs').tabs({
        onSelect: function(title,index){
            if(index == 1){
                $("#stay-datagrid1").datagrid('clearSelections');
            }
        }
    });*/
    
    function getName(objInfo, data) {
    if(objInfo && objInfo.$ref){
        objInfos = jsonPath(data, objInfo.$ref);
        return objInfos[0].name;
    }
    if(objInfo != null){
        return objInfo.name;
    }
    return "--";
}   
</script>
